# requests 是实现http请求的一种方式，是第三方模块，比urllib模块简化很多


import requests

# 1、get请求
# response = requests.get("http://www.baidu.com", timeout=0.5)  # 可选参数，timeout 超时时间
# html_doc = str(response.content, 'utf-8')  # 指定编码
# print(html_doc)
# print(response.status_code)  # 状态码
# print(response.url)  # 请求的url
# print(response.headers)  # 响应头
# print(response.cookies)  # cookie信息
# print(response.text)  # 以文本形式打印网页源码
# print(response.content)  # 以字节流形式打印网页源码

# 2、post请求
data = {"name": "Tom哥", "address": "hangzhou"}
headers = {'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
           'User-Agent': 'Moz illa/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
response = requests.post("http://127.0.0.1:8082/result", data=data, headers=headers)
print(response.headers)
html_doc = str(response.content, 'utf-8')  # 指定编码
print(html_doc)
